package com.mission.schedule.service;

import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mission.schedule.activity.NewFriendsActivity;
import com.mission.schedule.activity.RepeatTuiJianMoreActivity;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CalenderNoteBean;
import com.mission.schedule.bean.DownLoadBackBean;
import com.mission.schedule.bean.DownLoadBean;
import com.mission.schedule.bean.DownLoadRepeatBackBean;
import com.mission.schedule.bean.DownLoadRepeatBean;
import com.mission.schedule.bean.NoteTypeBean;
import com.mission.schedule.bean.RepeatUpAndDownBean;
import com.mission.schedule.bean.ScheduBean;
import com.mission.schedule.bean.SetBackBean;
import com.mission.schedule.bean.SetBean;
import com.mission.schedule.bean.WBA_FindFunctionMy;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.my160920.bean.FriendBackBean;
import com.mission.schedule.my160920.bean.FriendBean;
import com.mission.schedule.my160920.bean.FriendDeleteScheduleBean;
import com.mission.schedule.my160920.bean.FriendDownAllScheduleBean;
import com.mission.schedule.my160920.bean.FriendDownBackBean;
import com.mission.schedule.utils.CalendarChangeValue;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.XmlUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 网络数据下载操作，下载个人日程 日程分类，重复，本地联系人，清单标题，清单详情，清单分类，个人信息设置
 * Created by liwei on 2017/5/18.
 */

public class LoginDownDataService extends Service {
    String path = "";
    App application = App.getDBcApplication();
    SharedPrefUtil sharedPrefUtil = null;
    int index;
    List<Map<String, String>> soundlist = new ArrayList<Map<String, String>>();
    String UserId = "";
    String schyear;
    String schtime;
    String repyear;
    String reptime;
    Intent ServerDataDownLocalReceiver;
    String downreppath;
    CalendarChangeValue changeValue = new CalendarChangeValue();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onDestroy() {
        App.getHttpQueues().cancelAll("downCalender");
        App.getHttpQueues().cancelAll("downRepeat");
        App.getHttpQueues().cancelAll("DownFrendCalender");
        App.getHttpQueues().cancelAll("downNote");
        App.getHttpQueues().cancelAll("downNote1");
        App.getHttpQueues().cancelAll("downNote2");
        App.getHttpQueues().cancelAll("DownFrend");
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        soundlist.clear();
        soundlist = XmlUtil.readBeforeBellXML(this);
        sharedPrefUtil = new SharedPrefUtil(getApplication(), ShareFile.USERFILE);
        UserId = sharedPrefUtil.getString(getApplicationContext(),
                ShareFile.USERFILE, ShareFile.USERID, "");
        downtime = sharedPrefUtil.getString(
                getApplication(), ShareFile.USERFILE,
                ShareFile.UPDATENOTESETTIME, "2016-01-01%2B00:00:00");
        persondowntime = sharedPrefUtil.getString(getApplication(),
                ShareFile.USERFILE, ShareFile.PERSONDOWNTIME, "2016-01-01");
        String date = DateUtil.formatDateTimeSs(new Date());
        int year1 = Integer.parseInt(date.substring(0, 4).toString()) - 1;

        if ("0".equals(sharedPrefUtil.getString(getApplication(),
                ShareFile.USERFILE, ShareFile.FIRSTLOGIN, "0"))) {
            schyear = String.valueOf(year1)
                    + date.substring(4, 10).toString();
            schtime = date.substring(11, 19).toString();
            repyear = String.valueOf(year1)
                    + date.substring(4, 10).toString();
            reptime = date.substring(11, 19).toString();
        } else {
            String schdate = sharedPrefUtil.getString(
                    getApplication(), ShareFile.USERFILE,
                    ShareFile.DOWNSCHTIME, "");
            if (!"".equals(schdate)) {
                try {
                    schyear = schdate.substring(0, 10);
                    schtime = schdate.substring(11);
                } catch (Exception e) {
                    schyear = DateUtil.formatDate(new Date());
                    schtime = DateUtil.formatDateTimeSs(new Date()).substring(11);
                }
            } else {
                schyear = String.valueOf(year1)
                        + date.substring(4, 10).toString();
                schtime = date.substring(11, 19).toString();
            }
            String repdate = sharedPrefUtil.getString(
                    getApplication(), ShareFile.USERFILE,
                    ShareFile.DOWNREPTIME, "");
            if (!"".equals(repdate)) {
                try {
                    repyear = repdate.substring(0, 10);
                    reptime = repdate.substring(11);
                } catch (Exception e) {
                    repyear = DateUtil.formatDate(new Date());
                    reptime = DateUtil.formatDateTimeSs(new Date()).substring(11);
                }
            } else {
                repyear = String.valueOf(year1)
                        + date.substring(4, 10).toString();
                reptime = date.substring(11, 19).toString();
            }
        }
        downPersonImage();
        return super.onStartCommand(intent, flags, startId);
    }

    private void createNoteType() {
        noteTypeBean(0, "备忘录", 0, 0);
//        noteTypeBean(-1, "收到的", -1, -1);
        noteTypeBean(1, "工作", 1, 1);
        noteTypeBean(2, "生活", 2, 2);
        noteTypeBean(3, "其他", 3, 3);
        noteTypeBean(4, "分类A", 4, 4);
        noteTypeBean(5, "分类B", 5, 5);
        noteTypeBean(6, "分类C", 6, 6);
    }

    private void noteTypeBean(int localId, String name, int orderId, int styleid) {
        NoteTypeBean.ListBean bean = new NoteTypeBean.ListBean();
        bean.id = 0;
        bean.uid = Integer.valueOf(UserId);
        bean.content = name;
        bean.changeTime = DateUtil.formatDateTimeSs(new Date());
        bean.orderId = orderId;
        bean.styleId = styleid;
        bean.localId = localId;
        bean.remark = "";
        bean.remark1 = "";

        App.getDBcApplication().saveNoteTypeData(bean);
    }

    /**
     * 下载头像和小背景图片(对应登录的初始化数据)
     */
    private synchronized void downPersonImage() {
        createNoteType();
        new HttpUtils(5000).configCurrentHttpCacheExpiry(1000).send(HttpMethod.GET, URLConstants.管理员, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    try {
                        RepeatTuiJianMoreActivity.AdminBena backbean = gson.fromJson(responseInfo.result,
                                RepeatTuiJianMoreActivity.AdminBena.class);
                        if (backbean.status == 0) {
                            String[] admins = backbean.message.split(",");
                            for (String admin : admins) {
                                if (UserId.equals(admin)) {
                                    sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.ISADMIN, "1");
                                }
                            }
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {

            }
        });
        RequestParams params = new RequestParams();
        params.addBodyParameter("uId", UserId);
        params.addBodyParameter("pageNum", "2000");
        new HttpUtils(5000).send(HttpMethod.POST, URLConstants.本地通讯录下载, params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    try {
                        Gson gson = new Gson();
                        NewFriendsActivity.newFriendBean bean = gson.fromJson(responseInfo.result, NewFriendsActivity.newFriendBean.class);
                        if (bean.status == 0) {

                            List<NewFriendsActivity.newFriendBean.PageBean.ItemsBean> list = bean.page.items;

                            if (list != null) {
                                for (NewFriendsActivity.newFriendBean.PageBean.ItemsBean listBean : list) {
                                    App.getDBcApplication().saveNewFriendData(listBean, 0);
                                }
                            }
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Log.e("TAG", s);
            }
        });

        RequestParams params1 = new RequestParams();
        params1.addBodyParameter("changTime", "");
        new HttpUtils(5000).send(HttpMethod.POST, URLConstants.小程序表, params1, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    try {
                        Gson gson = new Gson();
                        WBA_FindFunctionMy bean = gson.fromJson(responseInfo.result, WBA_FindFunctionMy.class);
                        if (bean.status == 0) {
                            sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.tb_function_my, bean.downTime.replace('T',' '));
                            List<WBA_FindFunctionMy.ListBean> list = bean.list;

                            if (list != null) {
                                for (WBA_FindFunctionMy.ListBean listBean : list) {
                                    App.getDBcApplication().insert_tb_function_my(listBean);
                                }
                            }
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Log.e("TAG", s);
            }
        });

        new HttpUtils(5000).send(HttpMethod.GET, URLConstants.新积分 + "?uid=" + UserId, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    Gson gson = new Gson();
                    try {
                        LoginJfBean backbean = gson.fromJson(responseInfo.result, LoginJfBean.class);
                        if (backbean.status == 0) {
                            List<LoginJfBean.ListBean> list = backbean.list;
                            if (list != null && list.size() > 0) {
                                LoginJfBean.ListBean bean = list.get(0);
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.ZJF, bean.userScore + "");
                            }
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(HttpException e, String s) {
                Log.e("TAG", s);
            }
        });


        String backgroundname = sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.USERBACKGROUNDPATH, "");
        String image_head = sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.USERPHOTOPATH, "");
        String imageUrl = URLConstants.图片 + image_head + "&imageType=2&imageSizeType=3";
        String bpath = "";
        if ("".equals(StringUtils.getIsStringEqulesNull(backgroundname))) {
            bpath = URLConstants.默认背景图片;
        } else {
            bpath = URLConstants.默认背景图片 + "=" + backgroundname;
        }

        String dicr = Environment.getExternalStorageDirectory() + "/DCIM/";
        File outfile = new File(dicr, "TimeApp");
        // 如果文件不存在，则创建一个新文件
        if (!outfile.isDirectory()) {
            try {
                outfile.mkdir();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        if (backgroundname.isEmpty() && image_head.isEmpty()) {
            downPersonImageStatus(true);
        } else {
            Bitmap bitmapHead = BitmapFactory.decodeFile(outfile + "/" + image_head.replace('/', '0'));
            Bitmap bitmapBG = BitmapFactory.decodeFile(outfile + "/" + backgroundname.replace('/', '0'));

            if (bitmapHead == null) {
                Intent intent = new Intent(getApplicationContext(), DownImageService.class);
                intent.setAction("downimage");
                intent.putExtra("url", imageUrl);
                intent.putExtra("name", image_head.replace('/', '0'));
                startService(intent);
            }

            if (bitmapBG == null) {
                Intent intent = new Intent(getApplicationContext(), DownImageService.class);
                intent.setAction("downimage");
                intent.putExtra("url", bpath);
                intent.putExtra("name", backgroundname.replace('/', '0'));
                startService(intent);
            }
            downPersonImageStatus(false);
        }
    }

    private void downPersonImageStatus(boolean isFailed) {
        ServerDataDownLocalReceiver = new Intent("LoginDownDataReceiver");
        ServerDataDownLocalReceiver.putExtra("personimage", isFailed ? "personimage_false" : "personimage");
        sendBroadcast(ServerDataDownLocalReceiver);
        downPerson();
    }

    boolean isFailed = false;

    private void downDataStatus() {
        ServerDataDownLocalReceiver = new Intent("LoginDownDataReceiver");
        ServerDataDownLocalReceiver.putExtra("downData", isFailed ? "downData_false" : "downData");
        sendBroadcast(ServerDataDownLocalReceiver);
        Intent intentnewf = new Intent(getApplicationContext(), NoteDService.class);
        intentnewf.setAction("NoteDService");
        intentnewf.setPackage(getApplicationContext().getPackageName());
        getApplicationContext().startService(intentnewf);
        Intent intent = new Intent();
        intent.setAction(Const.SHUAXINDATA);
        intent.putExtra("data", "success");
        intent.putExtra("index", 1);
        intent.putExtra("what", 1);
        intent.putExtra("isLoginService", true);
        sendBroadcast(intent);
    }

    /**
     * 下载日程数据
     */
    private synchronized void downCalender() {
        Log.e("TAG", "下载日程数据");
        if (sharedPrefUtil.getString(getApplicationContext(),
                ShareFile.USERFILE, ShareFile.LOGINTYPE, "1").equals("1")) {
            sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.LOGINTYPE, "0");
        }

        StringRequest request = new StringRequest(Method.POST, URLConstants.数据下载同步, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (!TextUtils.isEmpty(s)) {

                    try {
                        Gson gson = new Gson();
                        DownLoadBackBean downLoadBean = gson.fromJson(s, DownLoadBackBean.class);

                        List<ScheduBean> list = null;
                        List<Integer> deleteID = null;
                        if (downLoadBean.status == 0) {
                            sharedPrefUtil.putString(
                                    getApplication(),
                                    ShareFile.USERFILE,
                                    ShareFile.DOWNSCHTIME,
                                    downLoadBean.message.replace("T", " "));
                            List<DownLoadBean> beans = downLoadBean.maps;
                            for (int k = 0; k < beans.size(); k++) {
                                deleteID = beans.get(k).delete;
                                list = beans.get(k).tbCalendar;
                            }
                            if (list != null && list.size() > 0) {
                                for (int i = 0; i < list.size(); i++) {
                                    if (list.get(i).cContent != null) {
                                        String ringcode = "";
                                        String ringdesc = "";
                                        for (int j = 0; j < soundlist.size(); j++) {
                                            String str = list.get(i).cAlarmSoundDesc.replace(".ogg", "");
                                            if (str.equals(soundlist.get(j).get("value"))) {
                                                ringcode = soundlist.get(j).get("value");
                                                ringdesc = soundlist.get(j).get("name");
                                                break;
                                            } else {
                                                ringcode = "g_88";
                                                ringdesc = "完成任务";
                                            }
                                        }
                                        String str = list.get(i).cUpdateTime.toString().replace("T", " ");
                                        int m = application.CheckCountSchData(list.get(i).cId);
                                        int aid = list.get(i).attentionid;
                                        int atype = list.get(i).aType;
                                        if (m == 0) {
                                            application.insertIntenetScheduleData(
                                                    list.get(i).cId,
                                                    list.get(i).cContent,
                                                    list.get(i).cDate,
                                                    list.get(i).cTime,
                                                    list.get(i).cIsAlarm,
                                                    list.get(i).cBeforTime,
                                                    list.get(i).cDisplayAlarm,
                                                    list.get(i).cPostpone,
                                                    list.get(i).cImportant,
                                                    list.get(i).cColorType,
                                                    list.get(i).cIsEnd,
                                                    str,
                                                    list.get(i).cTags,
                                                    list.get(i).cType,
                                                    list.get(i).cTypeDesc,
                                                    list.get(i).cTypeSpare,
                                                    list.get(i).cRepeatId,
                                                    list.get(i).cRepeatDate,
                                                    str,
                                                    0,
                                                    list.get(i).cOpenState,
                                                    list.get(i).cSchRepeatLink,
                                                    ringdesc,
                                                    ringcode,
                                                    list.get(i).cRecommendName,
                                                    list.get(i).schRead,
                                                    aid,
                                                    atype,
                                                    list.get(i).webUrl,
                                                    list.get(i).imgPath,
                                                    1,
                                                    0,
                                                    list.get(i).cRecommendId,
                                                    list.get(i).pIsEnd,
                                                    list.get(i).remark,
                                                    list.get(i).remark1,
                                                    list.get(i).remark2,
                                                    list.get(i).remark3,
                                                    list.get(i).remark4,list.get(i).remark7,
                                                    list.get(i).remark10,list.get(i).remark11,list.get(i).remark12);
                                        } else {
                                            application.updateScheduleData(
                                                    list.get(i).cId,
                                                    list.get(i).cContent,
                                                    list.get(i).cDate,
                                                    list.get(i).cTime,
                                                    list.get(i).cIsAlarm,
                                                    list.get(i).cBeforTime,
                                                    list.get(i).cDisplayAlarm,
                                                    list.get(i).cPostpone,
                                                    list.get(i).cImportant,
                                                    list.get(i).cColorType,
                                                    list.get(i).cIsEnd,
                                                    list.get(i).cTags,
                                                    list.get(i).cType,
                                                    list.get(i).cTypeDesc,
                                                    list.get(i).cTypeSpare,
                                                    list.get(i).cRepeatId,
                                                    list.get(i).cRepeatDate,
                                                    str,
                                                    0,
                                                    list.get(i).cOpenState,
                                                    list.get(i).cSchRepeatLink,
                                                    ringdesc,
                                                    ringcode,
                                                    list.get(i).cRecommendName,
                                                    list.get(i).schRead,
                                                    aid,
                                                    list.get(i).aType,
                                                    list.get(i).webUrl,
                                                    list.get(i).imgPath,
                                                    0,
                                                    0,
                                                    list.get(i).cRecommendId, list.get(i).pIsEnd, list.get(i).remark,list.get(i).remark1,
                                                    list.get(i).remark2,
                                                    list.get(i).remark3,
                                                    list.get(i).remark4,list.get(i).remark7,list.get(i).remark10,list.get(i).remark11,list.get(i).remark12);
                                        }
                                    }
                                }
                            }

                            if (deleteID != null && deleteID.size() > 0) {
                                for (int i = 0; i < deleteID.size(); i++) {
                                    application.deleteScheduleData(deleteID.get(i));
                                    application.deleteSch(deleteID.get(i));
                                }
                            }
                            QueryAlarmData.writeAlarm(getApplicationContext());
                            sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE, ShareFile.INDEX, index + "");
                        } else if (downLoadBean.status != 1 && downLoadBean.status != 0) {
                            sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE, ShareFile.INDEX, index + "");

                        }
                        sharedPrefUtil.putString(getApplication(),
                                ShareFile.USERFILE, ShareFile.DOWNSCHTIME,
                                downLoadBean.message.replace("T", " "));
                    } catch (Exception e) {
                        e.printStackTrace();
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true downCalender try catch");
                        sharedPrefUtil.putString(getApplication(),
                                ShareFile.USERFILE, ShareFile.INDEX, index + "");
                    }
                }
                downRepeat();
                Log.e("TAG", "日程数据下载完成");
            }

        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true downCalender network error");
                downRepeat();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("cUid", UserId);//张姐 260016
                map.put("beforDownTime", schyear);
                map.put("type", "1");

                return map;
            }
        };
        request.setTag("downCalender");
        request.setRetryPolicy(new DefaultRetryPolicy(20000, 1, 1.0f));
        App.getHttpQueues().add(request);

    }


    /**
     * 下载重复数据
     */
    private synchronized void downRepeat() {
        Log.e("TAG", "下载重复数据");
        StringRequest request = new StringRequest(Method.POST, URLConstants.重复数据下载, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (!TextUtils.isEmpty(s)) {

                    try {
                        Gson gson = new Gson();
                        DownLoadRepeatBackBean downLoadBean = gson.fromJson(s,
                                DownLoadRepeatBackBean.class);

                        List<DownLoadRepeatBean> beans;
                        List<RepeatUpAndDownBean> list = null;
                        List<Integer> deleteID = null;
                        if (downLoadBean.status == 0) {
                            sharedPrefUtil.putString(
                                    getApplication(),
                                    ShareFile.USERFILE,
                                    ShareFile.DOWNREPTIME,
                                    downLoadBean.message
                                            .replace("T", " "));
                            beans = downLoadBean.maps;
                            for (int k = 0; k < beans.size(); k++) {
                                deleteID = beans.get(k).delete;
                                list = beans.get(k).TbTtimepreinstall;
                            }

                            if (list != null && list.size() > 0) {
                                for (int i = 0; i < list.size(); i++) {
                                    String ringcode = "";
                                    String ringdesc = "";
                                    for (int j = 0; j < soundlist
                                            .size(); j++) {
                                        String str = list
                                                .get(i).repRingCode
                                                .replace(
                                                        ".ogg",
                                                        "");
                                        if (str.equals(soundlist
                                                .get(j)
                                                .get("value"))) {
                                            ringcode = soundlist
                                                    .get(j)
                                                    .get("value");
                                            ringdesc = soundlist
                                                    .get(j)
                                                    .get("name");
                                            break;
                                        } else {
                                            ringcode = "g_88";
                                            ringdesc = "完成任务";
                                        }
                                    }
                                    int index = 0;
                                    if (list.get(i).recommendedUserId != null
                                            && !"".equals(list.get(i).recommendedUserId)) {
                                        index = Integer.parseInt(list.get(i).recommendedUserId);
                                    }
                                    // 根据repid查询重复表，看下是否有repid相同的母记事
                                    int count = application.CheckCountRepData(Integer.parseInt(list.get(i).repId));
                                    if (count == 0) {
                                        if (("".equals(list.get(i).repTypeParameter) || "null".equals(list.get(i).repTypeParameter))
                                                && (!"1".equals(list.get(i).repType) || !"5".equals(list.get(i).repType))) {
                                            String typestr;
                                            int type;
                                            String parstr = "";
                                            if ("1".equals(list.get(i).repType)) {
                                                typestr = "[" + "" + "]";
                                                type = 1;
                                            } else if ("2".equals(list.get(i).repType)) {
                                                typestr = "[" + "1" + "]";
                                                type = 2;
                                            } else if ("3".equals(list.get(i).repType)) {
                                                typestr = "[" + "\"" + 1 + "\"" + "]";
                                                type = 3;
                                            } else if ("4".equals(list.get(i).repType)) {
                                                typestr = "[" + "\"" + "01-01" + "\"" + "]";
                                                type = 4;
                                            } else if ("6".equals(list.get(i).repType)) {
                                                typestr = "[" + "\"" + "正月初一" + "\"" + "]";
                                                type = 6;
                                                parstr = "01-01";
                                            } else {
                                                typestr = "[" + "" + "]";
                                                type = 5;
                                            }
                                            application.insertDownCLRepeatTableData(
                                                    Integer.parseInt(list.get(i).repId),
                                                    Integer.parseInt(list.get(i).repBeforeTime),
                                                    Integer.parseInt(list.get(i).repColorType),
                                                    Integer.parseInt(list.get(i).repDisplayTime),
                                                    Integer.parseInt(list.get(i).repType),
                                                    Integer.parseInt(list.get(i).repIsAlarm),
                                                    Integer.parseInt(list.get(i).repIsPuase),
                                                    Integer.parseInt(list.get(i).repIsImportant),
                                                    Integer.parseInt(list.get(i).repSourceType),
                                                    0,
                                                    list.get(i).repTypeParameter,
                                                    list.get(i).repNextCreatedTime.replace("T", " "),
                                                    list.get(i).repLastCreatedTime.replace("T", " "),
                                                    list.get(i).repInitialCreatedTime.replace("T", " "),
                                                    list.get(i).repStartDate.replace("T", " "),
                                                    list.get(i).repContent,
                                                    list.get(i).repCreateTime.replace("T", " "),
                                                    list.get(i).repSourceDesc,
                                                    list.get(i).repSourceDescSpare,
                                                    list.get(i).repTime,
                                                    ringdesc,
                                                    ringcode,
                                                    list.get(i).repUpdateTime.replace("T", " "),
                                                    Integer.parseInt(list.get(i).repOpenState),
                                                    list.get(i).recommendedUserName,
                                                    index,
                                                    list.get(i).repdateone,
                                                    list.get(i).repdatetwo,
                                                    Integer.parseInt(list.get(i).repstateone),
                                                    Integer.parseInt(list.get(i).repstatetwo),
                                                    list.get(i).aType,
                                                    list.get(i).webUrl,
                                                    list.get(i).imgPath,
                                                    list.get(i).repInSTable,
                                                    list.get(i).repEndState,
                                                    list.get(i).parReamrk,
                                                    list.get(i).repRead, 0,list.get(i).dataType,list.get(i).dataId,list.get(i).remark1,
                                                    list.get(i).remark2,list.get(i).remark3,list.get(i).remark4,list.get(i).remark5);

                                        } else {
                                            /**
                                             * 重复 每年
                                             */
                                            String parstr = "";
                                            if ("6".equals(list.get(i).repType)) {
                                                if (changeValue.changaSZ(list.get(i).repTypeParameter
                                                        .replace("[", "")
                                                        .replace("]", "")
                                                        .replace("\n\"", "")
                                                        .replace("\n", "")
                                                        .replace("\"", ""))
                                                        .length() == 2) {
                                                    parstr = DateUtil.formatDate(new Date()).substring(5, 7)
                                                            + "-"
                                                            + changeValue.changaSZ(list.get(i).repTypeParameter
                                                            .replace("[", "")
                                                            .replace("]", "")
                                                            .replace("\n\"", "")
                                                            .replace("\n", "")
                                                            .replace("\"", ""));
                                                } else {
                                                    parstr = changeValue.changaSZ(list.get(i).repTypeParameter
                                                            .replace("[", "")
                                                            .replace("]", "")
                                                            .replace("\n\"", "")
                                                            .replace("\n", "")
                                                            .replace("\"", ""));
                                                }
                                            }
                                            /**
                                             * 这里应该有判断
                                             */
                                            application.insertDownCLRepeatTableData(
                                                    Integer.parseInt(list.get(i).repId),
                                                    Integer.parseInt(list.get(i).repBeforeTime),
                                                    Integer.parseInt(list.get(i).repColorType),
                                                    Integer.parseInt(list.get(i).repDisplayTime),
                                                    Integer.parseInt(list.get(i).repType),
                                                    Integer.parseInt(list.get(i).repIsAlarm),
                                                    Integer.parseInt(list.get(i).repIsPuase),
                                                    Integer.parseInt(list.get(i).repIsImportant),
                                                    Integer.parseInt(list.get(i).repSourceType),
                                                    0,
                                                    list.get(i).repTypeParameter,
                                                    list.get(i).repNextCreatedTime.replace("T", " "),
                                                    list.get(i).repLastCreatedTime.replace("T", " "),
                                                    list.get(i).repInitialCreatedTime.replace("T", " "),
                                                    list.get(i).repStartDate.replace("T", " "),
                                                    list.get(i).repContent,
                                                    list.get(i).repCreateTime.replace("T", " "),
                                                    list.get(i).repSourceDesc,
                                                    list.get(i).repSourceDescSpare,
                                                    list.get(i).repTime,
                                                    ringdesc,
                                                    ringcode,
                                                    list.get(i).repUpdateTime.replace("T", " "),
                                                    Integer.parseInt(list.get(i).repOpenState),
                                                    list.get(i).recommendedUserName,
                                                    index,
                                                    list.get(i).repdateone,
                                                    list.get(i).repdatetwo,
                                                    Integer.parseInt(list.get(i).repstateone),
                                                    Integer.parseInt(list.get(i).repstatetwo),
                                                    list.get(i).aType,
                                                    list.get(i).webUrl,
                                                    list.get(i).imgPath,
                                                    list.get(i).repInSTable,
                                                    list.get(i).repEndState,
                                                    parstr,
                                                    list.get(i).repRead, 0,list.get(i).dataType,list.get(i).dataId,list.get(i).remark1,
                                                    list.get(i).remark2,list.get(i).remark3,list.get(i).remark4,list.get(i).remark5);
                                        }
                                        //是否生成子记事标记 0 生成
                                        if (list.get(i).repInSTable == 0) {
                                            //未暂停才生出
                                            if (Integer.valueOf(list.get(i).repIsPuase) == 0) {
                                                if (application.queryChildRepeatIsSave(
                                                        list.get(i).repContent,
                                                        list.get(i).repNextCreatedTime,
                                                        list.get(i).repId) == false) {
                                                    DownRepeatService.CreateRepeatSchNextData(list.get(i));
                                                }
                                            }
                                        }
                                    }
                                }
                                QueryAlarmData.writeAlarm(getApplicationContext());
                            }
                            if (deleteID != null && deleteID.size() > 0) {
                                for (int i = 0; i < deleteID.size(); i++) {
                                    application.deleteChildSch(deleteID.get(i) + "");
                                    application.deleteRepeatData(deleteID.get(i).toString());
                                    application.deleteSch(deleteID.get(i));
                                }
                            }
                            if ((list != null && list.size() > 0) || (deleteID != null && deleteID.size() > 0)) {
                                Intent intent = new Intent();
                                intent.setAction(DownRepeatService.RepUPDATADATA);
                                intent.putExtra("data", "success");
                                sendBroadcast(intent);
                            }

                        }
                        Intent intent = new Intent(Const.SHUAXINDATA);
                        intent.putExtra("data", "success");
                        intent.putExtra("index", 1);
                        intent.putExtra("what", 2);
                        sendBroadcast(intent);
                        sharedPrefUtil.putString(
                                getApplication(),
                                ShareFile.USERFILE,
                                ShareFile.DOWNREPTIME,
                                downLoadBean.message.replace("T", " "));
                    } catch (Exception e) {
                        e.printStackTrace();
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true downRepeat try catch");
                    }

                }
                downNote();
            }


        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true downRepeat network error");
                downNote();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("cUid", UserId);//260016
                map.put("beforDownTime", schyear);
                map.put("type", "1");

                return map;
            }
        };
        request.setTag("downRepeat");
        request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f));
        App.getHttpQueues().add(request);

    }

    /**
     * 下载清单数据
     */
    private synchronized void downNote() {
        Intent DownCa = new Intent(this, DownCalenderNoteService.class);
        DownCa.setAction("DownCalenderNoteService");
        DownCa.setPackage(getPackageName());
        startService(DownCa);
        Log.e("TAG", "下载清单数据");
        StringRequest request = new StringRequest(Method.POST, URLConstants.清单分类下载, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (!TextUtils.isEmpty(s)) {
                    try {
                        Gson gson = new Gson();
                        NoteTypeBean bean = gson.fromJson(s, NoteTypeBean.class);
                        if (bean.status == 0) {
                            List<NoteTypeBean.ListBean> list = bean.list;

                            if (list != null) {
                                Collections.sort(list, new Comparator<NoteTypeBean.ListBean>() {
                                    @Override
                                    public int compare(NoteTypeBean.ListBean lhs, NoteTypeBean.ListBean rhs) {
                                        return rhs.changeTime.compareTo(lhs.changeTime);
                                    }
                                });
                                for (int i = 0; i < list.size() - 1; i++) {
                                    for (int j = list.size() - 1; j > i; j--) {
                                        if (list.get(j).localId == list.get(i).localId) {
                                            list.remove(j);
                                        }
                                    }
                                }
                                for (NoteTypeBean.ListBean listBean : list) {
                                    App.getDBcApplication().saveNoteTypeData(listBean);
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }


        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true userDetail_downTbuserDetailType error");
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("uId", UserId);

                return map;
            }
        };
        request.setTag("downNote1");
        request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f));
        App.getHttpQueues().add(request);

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                RequestParams params = new RequestParams();
                params.addBodyParameter("uid", UserId);
                params.addBodyParameter("changeTime", "2017-10-01");
                params.addBodyParameter("nowpage", "1");
                params.addBodyParameter("pageNum", "2000");
                new HttpUtils(10000).send(HttpMethod.POST, URLConstants.日程清单下载, params, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        if (!TextUtils.isEmpty(responseInfo.result)) {
                            try {
                                Gson gson = new Gson();
                                CalenderNoteBean bean = gson.fromJson(responseInfo.result, CalenderNoteBean.class);
                                if (bean.status == 0) {
                                    List<CalenderNoteBean.PageBean.ItemsBean> itemsBeanList = bean.page.items;

                                    if (itemsBeanList != null) {
                                        for (CalenderNoteBean.PageBean.ItemsBean itemsBean : itemsBeanList) {
                                            App.getDBcApplication().saveCalederNoteDetailData(itemsBean);
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                isFailed = true;
                                Log.i("isFailed", "isFailed = true schedule_downTbCalendarListClass try");
                            }
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, String s) {
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true schedule_downTbCalendarListClass error");
                    }
                });
            }
        });

        new Handler().post(new Runnable() {
            @Override
            public void run() {
                RequestParams params = new RequestParams();
                params.addBodyParameter("cUid", UserId);
                params.addBodyParameter("changeTime", "2017-10-01");
                params.addBodyParameter("nowpage", "1");
                params.addBodyParameter("pageNum", "2000");
                new HttpUtils(10000).send(HttpMethod.POST, URLConstants.重复清单下载, params, new RequestCallBack<String>() {
                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        if (!TextUtils.isEmpty(responseInfo.result)) {
                            try {
                                Gson gson = new Gson();
                                CalenderNoteBean bean = gson.fromJson(responseInfo.result, CalenderNoteBean.class);
                                if (bean.status == 0) {
                                    List<CalenderNoteBean.PageBean.ItemsBean> itemsBeanList = bean.page.items;

                                    if (itemsBeanList != null) {
                                        for (CalenderNoteBean.PageBean.ItemsBean itemsBean : itemsBeanList) {
                                            App.getDBcApplication().saveCalederNoteDetailData(itemsBean);
                                        }
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                isFailed = true;
                                Log.i("isFailed", "isFailed = true schedule_downTbCalendarListClass try");
                            }
                        }
                    }

                    @Override
                    public void onFailure(HttpException e, String s) {
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true schedule_downTbCalendarListClass error");
                    }
                });
            }
        });


        StringRequest request1 = new StringRequest(Method.POST, URLConstants.清单和清单标题下行, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (!TextUtils.isEmpty(s)) {
                    try {
                        Gson gson = new Gson();
                        NoteTitleDetailBean bean = gson.fromJson(s, NoteTitleDetailBean.class);
                        if (bean.status == 0) {
                            sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE, ShareFile.LOGINNOTEDATA, s);
                            sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE,
                                    ShareFile.UPDATENOTESETTIME, bean.downTime.replace('T', ' '));
                            List<NoteTitleDetailBean.TDelListBean> tDelList = bean.tDelList;
                            List<NoteTitleDetailBean.ListBean> beanList = bean.list;
                            List<NoteTitleDetailBean.DelListBean> delList = bean.delList;

                            if (tDelList != null) {
                                boolean isTitleBWL = false;
                                for (NoteTitleDetailBean.TDelListBean tDelListBean : tDelList) {
                                    if (tDelListBean.titles.equals("备忘录")) {
                                        if (!isTitleBWL) {
                                            App.getDBcApplication().saveNoteTitleData(tDelListBean);
                                        }
                                        isTitleBWL = true;
                                    } else {
                                        App.getDBcApplication().saveNoteTitleData(tDelListBean);
                                    }
                                }
                            }

//                            if (beanList != null) {
//                                for (NoteTitleDetailBean.ListBean listBean : beanList) {
//                                    if (!listBean.contents.isEmpty()) {
//                                        App.getDBcApplication().saveNoteDetailData(listBean);
//                                    }
//                                }
//                            }

                            if (delList != null) {
                                for (NoteTitleDetailBean.DelListBean delListBean : delList) {
                                    App.getDBcApplication().deleteNote(delListBean.type, delListBean.dataId);
                                }
                            }
                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true userDetail_downTbUserDetailAndDetailTitle try");
                    }
                }
                DownFrend();
                Log.i("Note", "清单数据操作完成");
            }


        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true userDetail_downTbUserDetailAndDetailTitle error");
                DownFrend();
            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("uId", UserId);
                map.put("changeTime", "2016-06-01");
                Log.i("Note", "开始下行清单数据");
                return map;
            }
        };
        request1.setTag("downNote2");
        request1.setRetryPolicy(new DefaultRetryPolicy(20000, 1, 1.0f));
        App.getHttpQueues().add(request1);

    }


    String downtime = "2016-01-01%2B00:00:00";
    String persondowntime = "2016-01-01";

    /**
     * 下载好友信息
     */

    public synchronized void DownFrend() {
        Intent pull = new Intent();
        pull.setAction("pullRecevier");
        getApplication().sendBroadcast(pull);
        Log.e("TAG", "下载好友信息");
        StringRequest request = new StringRequest(Method.POST, URLConstants.HOST + "/appFrends_findFrendsSay.do",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String result) {
                        if (!TextUtils.isEmpty(result)) {
                            try {
                                Gson gson = new Gson();

                                FriendBackBean friendBackBean = gson.fromJson(result, FriendBackBean.class);
                                if (friendBackBean.status == 0) {

                                    List<FriendBean> friendBeanList = friendBackBean.list;
                                    if (friendBeanList != null) {

                                        for (FriendBean bean : friendBeanList) {
                                            App.getDBcApplication().insertFriendsList(bean);
                                        }

                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                                isFailed = true;
                                Log.i("isFailed", "isFailed = true appFrends_findFrendsSay try");
                            }
                        }
                        DownFrendCalender();
                    }

                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true appFrends_findFrendsSay error");
                DownFrendCalender();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("uId", UserId);// "52432"
                map.put("updateTime", "2016-06-01");//"2015-01-01 00:00:00"
                return map;
            }
        };
        request.setTag("DownFrend");
        request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f));
        App.getHttpQueues().add(request);
    }


    /**
     * 下载所有日程信息
     */
    public synchronized void DownFrendCalender() {
        Log.e("TAG", "下载所有日程信息_L");
        StringRequest request = new StringRequest(Method.POST, URLConstants.HOST + "/appFrends_downFrendsCalendar.do", new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (!TextUtils.isEmpty(s)) {
                    try {
                        Gson gson = new Gson();

                        FriendDownBackBean findFrendsSayBean = gson.fromJson(s, FriendDownBackBean.class);
                        if (findFrendsSayBean.status == 0) {

                            sharedPrefUtil.putString(getApplication(), ShareFile.USERFILE, ShareFile.PERSONDOWNTIME,
                                            findFrendsSayBean.downTime.replace('T', ' '));

                            List<FriendDownAllScheduleBean> firendDownBeanList = findFrendsSayBean.list;
                            List<FriendDeleteScheduleBean> friendDeleteScheduleBeanList = findFrendsSayBean.delList;
                            if (firendDownBeanList != null) {
                                for (FriendDownAllScheduleBean bean : firendDownBeanList) {
                                    App.getDBcApplication().insertFriendSchedule(bean);
                                }
                            }
                            if (friendDeleteScheduleBeanList != null) {
                                for (FriendDeleteScheduleBean bean : friendDeleteScheduleBeanList) {
                                    App.getDBcApplication().deleteFriendSchedule(bean.dataId);
                                }
                            }
                            Log.e("TAG", "下载所有日程信息end");

                        }
                    } catch (Exception e) {
                        isFailed = true;
                        Log.i("isFailed", "isFailed = true appFrends_downFrendsCalendar try");
                        e.printStackTrace();
                    }
                }
                downDataStatus();
            }


        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                isFailed = true;
                Log.i("isFailed", "isFailed = true appFrends_downFrendsCalendar error");
                downDataStatus();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                map.put("uId", UserId);
                map.put("updateTime", "2016-01-01");
                return map;
            }
        };
        request.setTag("DownFrendCalender");
        request.setRetryPolicy(new DefaultRetryPolicy(5000, 1, 1.0f));
        App.getHttpQueues().add(request);
    }


    /**
     * 下载个人信息
     */
    private synchronized void downPerson() {
        final String updatetime = sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.UPDATESETTIME, "");
        String querysetPath = URLConstants.查询设置信息 + UserId;
        new HttpUtils(5000).configCurrentHttpCacheExpiry(1000).send(HttpMethod.GET, querysetPath, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {
                if (!TextUtils.isEmpty(responseInfo.result)) {
                    try {
                        Gson gson = new Gson();
                        SetBackBean backBean = gson.fromJson(responseInfo.result,
                                SetBackBean.class);
                        if (backBean.status == 0) {
                            List<SetBean> list = backBean.list;
                            if ("".equals(updatetime)) {
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MUSICDESC, list.get(0).ringDesc + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MUSICCODE, list.get(0).ringCode + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.BEFORETIME, list.get(0).beforeTime + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MORNINGSTATE, list.get(0).morningState + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MORNINGTIME, list.get(0).morningTime + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.NIGHTSTATE, list.get(0).nightState + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.NIGHTTIME, list.get(0).nightTime + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.ALLSTATE, list.get(0).dayState + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.ALLTIME, list.get(0).dayTime + "");
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.UPDATESETTIME, list.get(0).updateTime.replace("T", " "));
                                sharedPrefUtil.putString(getApplicationContext(), ShareFile.USERFILE, ShareFile.SETID, list.get(0).id + "");
                                String today, tomorrow;
                                Calendar calendar = Calendar.getInstance();
                                calendar.setTime(new Date());
                                today = DateUtil.formatDate(calendar.getTime());
                                calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
                                tomorrow = DateUtil.formatDate(calendar.getTime());
                                if ("0".equals(sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MORNINGSTATE, "0"))) {
                                    int count = App.getDBcApplication().CheckClockIDData(-1);
                                    if (count == 0) {
                                        if (DateUtil.parseDateTimeHm(sharedPrefUtil.getString(getApplicationContext(), ShareFile.USERFILE, ShareFile.MORNINGTIME, "07:58"))
                                                .before(DateUtil.parseDateTimeHm(DateUtil.formatDateTimeHm(new Date())))) {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(-1, DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow + " " + sharedPrefUtil.getString(
                                                                            getApplicationContext(),
                                                                            ShareFile.USERFILE,
                                                                            ShareFile.MORNINGTIME,
                                                                            "07:58"))),
                                                            "早上问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "",
                                                            "morninghello.wav",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        } else {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -1,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "早上问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "",
                                                            "morninghello.wav",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        }
                                    } else {
                                        App.getDBcApplication()
                                                .deleteEveryClock(
                                                        -1);
                                        if (DateUtil.parseDateTimeHm(sharedPrefUtil.getString(
                                                getApplicationContext(),
                                                ShareFile.USERFILE,
                                                ShareFile.MORNINGTIME,
                                                "07:58")).before(DateUtil.parseDateTimeHm(DateUtil.formatDateTimeHm(new Date())))) {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -1,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "早上问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "",
                                                            "morninghello.wav",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        } else {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -1,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "早上问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.MORNINGTIME,
                                                                                    "07:58"))),
                                                            "",
                                                            "morninghello.wav",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        }
                                    }
                                } else {
                                    App.getDBcApplication()
                                            .deleteEveryClock(-1);
                                }
                                if ("0".equals(sharedPrefUtil
                                        .getString(
                                                getApplicationContext(),
                                                ShareFile.USERFILE,
                                                ShareFile.NIGHTSTATE,
                                                "0"))) {

                                    int count = App
                                            .getDBcApplication()
                                            .CheckClockIDData(-2);
                                    if (count == 0) {
                                        if (DateUtil
                                                .parseDateTimeHm(
                                                        sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"))
                                                .before(DateUtil
                                                        .parseDateTimeHm(DateUtil
                                                                .formatDateTimeHm(new Date())))) {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -2,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "下午问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "",
                                                            "nighthello.ogg",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        } else {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -2,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "下午问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "",
                                                            "nighthello.ogg",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        }
                                    } else {
                                        App.getDBcApplication()
                                                .deleteEveryClock(
                                                        -2);
                                        if (DateUtil
                                                .parseDateTimeHm(
                                                        sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"))
                                                .before(DateUtil
                                                        .parseDateTimeHm(DateUtil
                                                                .formatDateTimeHm(new Date())))) {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -2,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "下午问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(tomorrow
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "",
                                                            "nighthello.ogg",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        } else {
                                            App.getDBcApplication()
                                                    .insertEveryClockData(
                                                            -2,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "下午问候",
                                                            0,
                                                            DateUtil.formatDateTimeSs(DateUtil
                                                                    .parseDateTime(today
                                                                            + " "
                                                                            + sharedPrefUtil
                                                                            .getString(
                                                                                    getApplicationContext(),
                                                                                    ShareFile.USERFILE,
                                                                                    ShareFile.NIGHTTIME,
                                                                                    "20:58"))),
                                                            "",
                                                            "nighthello.ogg",
                                                            1, 1,
                                                            7, 0,
                                                            0, 1,
                                                            0, "",
                                                            0, 0,
                                                            "", "");
                                        }
                                    }
                                } else {
                                    App.getDBcApplication()
                                            .deleteEveryClock(-2);
                                }
                            } else {
                                if (DateUtil
                                        .parseDateTimeSs(
                                                list.get(0).updateTime
                                                        .replace(
                                                                "T",
                                                                " "))
                                        .after(DateUtil.parseDateTimeSs(updatetime))) {
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.MUSICDESC,
                                            list.get(0).ringDesc
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.MUSICCODE,
                                            list.get(0).ringCode
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.BEFORETIME,
                                            list.get(0).beforeTime
                                                    + "");
                                    sharedPrefUtil
                                            .putString(
                                                    getApplicationContext(),
                                                    ShareFile.USERFILE,
                                                    ShareFile.MORNINGSTATE,
                                                    list.get(0).morningState
                                                            + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.MORNINGTIME,
                                            list.get(0).morningTime
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.NIGHTSTATE,
                                            list.get(0).nightState
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.NIGHTTIME,
                                            list.get(0).nightTime
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.ALLSTATE,
                                            list.get(0).dayState
                                                    + "");
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.ALLTIME,
                                            list.get(0).dayTime
                                                    + "");
                                    sharedPrefUtil
                                            .putString(
                                                    getApplicationContext(),
                                                    ShareFile.USERFILE,
                                                    ShareFile.UPDATESETTIME,
                                                    list.get(0).updateTime
                                                            .replace(
                                                                    "T",
                                                                    " "));
                                    sharedPrefUtil.putString(
                                            getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.SETID,
                                            list.get(0).id + "");
                                    String today, tomorrow;
                                    Calendar calendar = Calendar
                                            .getInstance();
                                    calendar.setTime(new Date());
                                    today = DateUtil
                                            .formatDate(calendar
                                                    .getTime());
                                    calendar.set(
                                            Calendar.DAY_OF_MONTH,
                                            calendar.get(Calendar.DAY_OF_MONTH) + 1);
                                    tomorrow = DateUtil
                                            .formatDate(calendar
                                                    .getTime());
                                    if ("0".equals(sharedPrefUtil
                                            .getString(
                                                    getApplicationContext(),
                                                    ShareFile.USERFILE,
                                                    ShareFile.MORNINGSTATE,
                                                    "0"))) {
                                        int count = App
                                                .getDBcApplication()
                                                .CheckClockIDData(
                                                        -1);
                                        if (count == 0) {
                                            if (DateUtil
                                                    .parseDateTimeHm(
                                                            sharedPrefUtil
                                                                    .getString(
                                                                            getApplicationContext(),
                                                                            ShareFile.USERFILE,
                                                                            ShareFile.MORNINGTIME,
                                                                            "07:58"))
                                                    .before(DateUtil
                                                            .parseDateTimeHm(DateUtil
                                                                    .formatDateTimeHm(new Date())))) {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -1,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "早上问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "",
                                                                "morninghello.wav",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            } else {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -1,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "早上问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "",
                                                                "morninghello.wav",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            }
                                        } else {
                                            App.getDBcApplication()
                                                    .deleteEveryClock(
                                                            -1);
                                            if (DateUtil
                                                    .parseDateTimeHm(
                                                            sharedPrefUtil
                                                                    .getString(
                                                                            getApplicationContext(),
                                                                            ShareFile.USERFILE,
                                                                            ShareFile.MORNINGTIME,
                                                                            "07:58"))
                                                    .before(DateUtil
                                                            .parseDateTimeHm(DateUtil
                                                                    .formatDateTimeHm(new Date())))) {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -1,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "早上问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "",
                                                                "morninghello.wav",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            } else {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -1,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "早上问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.MORNINGTIME,
                                                                                        "07:58"))),
                                                                "",
                                                                "morninghello.wav",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            }
                                        }
                                    } else {
                                        App.getDBcApplication()
                                                .deleteEveryClock(
                                                        -1);
                                    }
                                    if ("0".equals(sharedPrefUtil
                                            .getString(
                                                    getApplicationContext(),
                                                    ShareFile.USERFILE,
                                                    ShareFile.NIGHTSTATE,
                                                    "0"))) {

                                        int count = App
                                                .getDBcApplication()
                                                .CheckClockIDData(
                                                        -2);
                                        if (count == 0) {
                                            if (DateUtil
                                                    .parseDateTimeHm(
                                                            sharedPrefUtil
                                                                    .getString(
                                                                            getApplicationContext(),
                                                                            ShareFile.USERFILE,
                                                                            ShareFile.NIGHTTIME,
                                                                            "20:58"))
                                                    .before(DateUtil
                                                            .parseDateTimeHm(DateUtil
                                                                    .formatDateTimeHm(new Date())))) {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -2,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "下午问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "",
                                                                "nighthello.ogg",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            } else {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -2,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "下午问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "",
                                                                "nighthello.ogg",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            }
                                        } else {
                                            App.getDBcApplication()
                                                    .deleteEveryClock(
                                                            -2);
                                            if (DateUtil
                                                    .parseDateTimeHm(
                                                            sharedPrefUtil
                                                                    .getString(
                                                                            getApplicationContext(),
                                                                            ShareFile.USERFILE,
                                                                            ShareFile.NIGHTTIME,
                                                                            "20:58"))
                                                    .before(DateUtil
                                                            .parseDateTimeHm(DateUtil
                                                                    .formatDateTimeHm(new Date())))) {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -2,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "下午问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(tomorrow
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "",
                                                                "nighthello.ogg",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            } else {
                                                App.getDBcApplication()
                                                        .insertEveryClockData(
                                                                -2,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "下午问候",
                                                                0,
                                                                DateUtil.formatDateTimeSs(DateUtil
                                                                        .parseDateTime(today
                                                                                + " "
                                                                                + sharedPrefUtil
                                                                                .getString(
                                                                                        getApplicationContext(),
                                                                                        ShareFile.USERFILE,
                                                                                        ShareFile.NIGHTTIME,
                                                                                        "20:58"))),
                                                                "",
                                                                "nighthello.ogg",
                                                                1,
                                                                1,
                                                                7,
                                                                0,
                                                                0,
                                                                1,
                                                                0,
                                                                "",
                                                                0,
                                                                0,
                                                                "",
                                                                "");
                                            }
                                        }
                                    } else {
                                        App.getDBcApplication()
                                                .deleteEveryClock(
                                                        -2);
                                    }
                                } else {

                                }
                            }
                        } else if (backBean.status == 1) {
                            String today, tomorrow;
                            Calendar calendar = Calendar
                                    .getInstance();
                            calendar.setTime(new Date());
                            today = DateUtil.formatDate(calendar
                                    .getTime());
                            calendar.set(
                                    Calendar.DAY_OF_MONTH,
                                    calendar.get(Calendar.DAY_OF_MONTH) + 1);
                            tomorrow = DateUtil.formatDate(calendar
                                    .getTime());
                            if ("0".equals(sharedPrefUtil
                                    .getString(getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.MORNINGSTATE,
                                            "0"))) {
                                int count = App.getDBcApplication()
                                        .CheckClockIDData(-1);
                                if (count == 0) {
                                    if (DateUtil
                                            .parseDateTimeHm(
                                                    sharedPrefUtil
                                                            .getString(
                                                                    getApplicationContext(),
                                                                    ShareFile.USERFILE,
                                                                    ShareFile.MORNINGTIME,
                                                                    "07:58"))
                                            .before(DateUtil
                                                    .parseDateTimeHm(DateUtil
                                                            .formatDateTimeHm(new Date())))) {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -1,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "早上问候",
                                                        0,
                                                        DateUtil.formatDateTime(new Date())
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "",
                                                        "morninghello.wav",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    } else {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -1,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "早上问候",
                                                        0,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "",
                                                        "morninghello.wav",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    }

                                } else {
                                    App.getDBcApplication()
                                            .deleteEveryClock(-1);
                                    if (DateUtil
                                            .parseDateTimeHm(
                                                    sharedPrefUtil
                                                            .getString(
                                                                    getApplicationContext(),
                                                                    ShareFile.USERFILE,
                                                                    ShareFile.MORNINGTIME,
                                                                    "07:58"))
                                            .before(DateUtil
                                                    .parseDateTimeHm(DateUtil
                                                            .formatDateTimeHm(new Date())))) {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -1,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "早上问候",
                                                        0,
                                                        DateUtil.formatDateTime(new Date())
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "",
                                                        "morninghello.wav",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    } else {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -1,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "早上问候",
                                                        0,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.MORNINGTIME,
                                                                        "07:58"),
                                                        "",
                                                        "morninghello.wav",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    }
                                }
                            } else {
                                App.getDBcApplication()
                                        .deleteEveryClock(-1);
                            }
                            if ("0".equals(sharedPrefUtil
                                    .getString(getApplicationContext(),
                                            ShareFile.USERFILE,
                                            ShareFile.NIGHTSTATE,
                                            "0"))) {

                                int count = App.getDBcApplication()
                                        .CheckClockIDData(-2);
                                if (count == 0) {
                                    if (DateUtil
                                            .parseDateTimeHm(
                                                    sharedPrefUtil
                                                            .getString(
                                                                    getApplicationContext(),
                                                                    ShareFile.USERFILE,
                                                                    ShareFile.NIGHTTIME,
                                                                    "20:58"))
                                            .before(DateUtil
                                                    .parseDateTimeHm(DateUtil
                                                            .formatDateTimeHm(new Date())))) {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -2,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "下午问候",
                                                        0,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "",
                                                        "nighthello.ogg",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    } else {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -2,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "下午问候",
                                                        0,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "",
                                                        "nighthello.ogg",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    }
                                } else {
                                    App.getDBcApplication()
                                            .deleteEveryClock(-2);
                                    if (DateUtil
                                            .parseDateTimeHm(
                                                    sharedPrefUtil
                                                            .getString(
                                                                    getApplicationContext(),
                                                                    ShareFile.USERFILE,
                                                                    ShareFile.NIGHTTIME,
                                                                    "20:58"))
                                            .before(DateUtil
                                                    .parseDateTimeHm(DateUtil
                                                            .formatDateTimeHm(new Date())))) {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -2,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "下午问候",
                                                        0,
                                                        tomorrow
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "",
                                                        "nighthello.ogg",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    } else {
                                        App.getDBcApplication()
                                                .insertEveryClockData(
                                                        -2,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "下午问候",
                                                        0,
                                                        today
                                                                + " "
                                                                + sharedPrefUtil
                                                                .getString(
                                                                        getApplicationContext(),
                                                                        ShareFile.USERFILE,
                                                                        ShareFile.NIGHTTIME,
                                                                        "20:58"),
                                                        "",
                                                        "nighthello.ogg",
                                                        1, 1, 7, 0,
                                                        0, 1, 0,
                                                        "", 0, 0,
                                                        "", "");
                                    }
                                }
                            } else {
                                App.getDBcApplication().deleteEveryClock(-2);
                            }

                        }
                    } catch (JsonSyntaxException e) {
                        e.printStackTrace();
                    }
                }
                downPersonStatus(false);
            }

            @Override
            public void onFailure(HttpException e, String s) {
                downPersonStatus(true);
            }
        });
    }


    private void downPersonStatus(boolean isFailed) {
        ServerDataDownLocalReceiver = new Intent("LoginDownDataReceiver");
        ServerDataDownLocalReceiver.putExtra("downperson", isFailed ? "downperson_false" : "downperson");
        sendBroadcast(ServerDataDownLocalReceiver);
//        downCalender();
        downCalender();
    }


    class LoginJfBean {

        private String downTime;
        private Object list2;
        private Object listOpdata;
        private String message;
        private Object page;
        private int status;
        private List<ListBean> list;

        public String getDownTime() {
            return downTime;
        }

        public void setDownTime(String downTime) {
            this.downTime = downTime;
        }

        public Object getList2() {
            return list2;
        }

        public void setList2(Object list2) {
            this.list2 = list2;
        }

        public Object getListOpdata() {
            return listOpdata;
        }

        public void setListOpdata(Object listOpdata) {
            this.listOpdata = listOpdata;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public Object getPage() {
            return page;
        }

        public void setPage(Object page) {
            this.page = page;
        }

        public int getStatus() {
            return status;
        }

        public void setStatus(int status) {
            this.status = status;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public class ListBean {
            /**
             * openCount : 1
             * userScore : 1303.5
             * state : 0
             * dayScore : 0.0
             * mess :
             * cdate : 2018-07-24
             * qcdate : 2018-07-12
             * frendScore : 0.99
             */

            private int openCount;
            private double userScore;
            private int state;
            private double dayScore;
            private String mess;
            private String cdate;
            private String qcdate;
            private double frendScore;

            public int getOpenCount() {
                return openCount;
            }

            public void setOpenCount(int openCount) {
                this.openCount = openCount;
            }

            public double getUserScore() {
                return userScore;
            }

            public void setUserScore(double userScore) {
                this.userScore = userScore;
            }

            public int getState() {
                return state;
            }

            public void setState(int state) {
                this.state = state;
            }

            public double getDayScore() {
                return dayScore;
            }

            public void setDayScore(double dayScore) {
                this.dayScore = dayScore;
            }

            public String getMess() {
                return mess;
            }

            public void setMess(String mess) {
                this.mess = mess;
            }

            public String getCdate() {
                return cdate;
            }

            public void setCdate(String cdate) {
                this.cdate = cdate;
            }

            public String getQcdate() {
                return qcdate;
            }

            public void setQcdate(String qcdate) {
                this.qcdate = qcdate;
            }

            public double getFrendScore() {
                return frendScore;
            }

            public void setFrendScore(double frendScore) {
                this.frendScore = frendScore;
            }
        }
    }
}
